package com.lagou.homework.stage01.module3;

import java.util.Scanner;

public class Task2 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.println("Please input first string :");
        String str1 = sc.next();
        System.out.println("Please input second string :");
        String str2 = sc.next();

        //str1存放长度小的字符串
        String tmp;
        if (str1.length() > str2.length()) {
            tmp = str1;
            str1 = str2;
            str2 = tmp;
        }

        tmp = null;
        here:
        for (int i = str1.length(); i > 0; i--) {                //i表示子字符串的长度
            for (int j = 0; j <= str1.length() - i; j++) {       //j表示子字符串从str1中索引为j的元素开始
                if (str2.contains(str1.substring(j, j + i))) {
                    tmp = str1.substring(j, j + i);
                    break here;
                }
            }
        }
        if (null != tmp) {
            System.out.println("lager sub string: " + tmp);
        } else {
            System.out.println("no sub string !");
        }

    }
}
